home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-30 | 6.1 KB | 258 lines | [TEXT/KAHL] |
- /***********************************************************************************
- CExpanderPane.h
-
- Copyright © 1994 B-Ray Software. All rights reserved.
- Developed using Symantec C++ 7.0.2 and Symantec's TCL library.
- Portions of this code courtesy Symantec, Inc.
-
- This code may be freely distributed as long as this notice remains. This code
- may not be used in any commercial software without the consent of B-Ray Software.
-
- ---
-
- CExpanderPane brings together the CPane and CColumnizer classes and provides the
- appropriate linkage to make them work together.
-
- ***********************************************************************************/
- #include "CExpanderPane.h"
- #include "ExpanderMessages.h"
-
- TCL_DEFINE_CLASS_D2( CExpanderPane, CPane, CColumnizer );
-
-
- /*
- * CExpanderPane constructor
- *
- * Default constructor - should only be called when created by a file read.
- */
-
- CExpanderPane :: CExpanderPane() : CPane(), CColumnizer()
- {
- selected = FALSE;
- canSelect = FALSE;
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /*
- * CExpanderPane constructor
- *
- * Normal constructor - should always be called when creating a new
- * CExpanderPane object in code.
- */
-
- CExpanderPane :: CExpanderPane( CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHLoc, short aVLoc,
- SizingOption aHSizing, SizingOption aVSizing )
- : CPane( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
- aHSizing, aVSizing ), CColumnizer()
- {
- UseLongCoordinates( TRUE );
- selected = FALSE;
- canSelect = FALSE;
-
- TCL_END_CONSTRUCTOR
- }
-
-
- /*
- * CExpanderPane destructor
- *
- * Just a place-holder for Inspector.
- */
-
- CExpanderPane :: ~CExpanderPane()
- {
- TCL_START_DESTRUCTOR
- }
-
-
- /*
- * ChangeSelf method - OVERRIDE
- *
- * Resizes ourselves based on the sizes of our children.
- */
-
- void CExpanderPane :: ChangeSelf( long changedIndex, Rect *delta )
- {
- short aHeight, aWidth;
-
- GetFamilySize( &aWidth, &aHeight ); // get dimensions of rectangle that contain our children
- SetExpanderSize( aWidth, aHeight ); // become that rectangle
- }
-
-
- /*
- * SetExpanderSize method
- *
- * Utilizes ChangeSize method to change our size. Afterwards, tells parent
- * that we have changed.
- */
-
- void CExpanderPane :: SetExpanderSize( short aWidth, short aHeight )
- {
- Rect delta = { 0, 0, 0, 0 };
-
- delta.right = aWidth - width; // create change dimensions
- delta.bottom = aHeight - height;
- if ( delta.right || delta.bottom ) {
- ChangeSize( &delta, TRUE ); // change frame
- TellParent( kRowColChildChanged, &delta ); // tell parent of our change
- }
- }
-
-
- /*
- * SetSelectedState method
- *
- * Begins process that selects a pane for hilighting. If the pane cannot be selected,
- * or the state is FALSE, then no pane will be selected.
- */
-
- void CExpanderPane :: SetSelectedState( Boolean aFlag )
- {
- TellParent( kExpanderChildSelect, ( aFlag && canSelect ) ? PaneToChild() : NULL );
- }
-
-
- /*
- * DoClick method - OVERRIDE
- *
- * Handles a mouse click in the pane's area. If the mouse is let up in the
- * pane, and the pane is selectable, then the pane will become selected.
- */
-
- void CExpanderPane :: DoClick( Point hitPt, short modifierKeys, long when )
- {
- Boolean wasInButton = TRUE;
- Point where;
- Rect btnFrame;
-
- if ( ! canSelect ) // don't even bother if we can't be selected
- return;
-
- Prepare();
-
- LongToQDRect( &frame, &btnFrame ); // get QD coordinates
-
- while ( StillDown() ) { // watch mouse until button is up
- GetMouse( &where );
- wasInButton = PtInRect( where, &btnFrame );
- };
-
- if ( wasInButton ) {
- SetSelectedState( TRUE ); // change our state
- }
- }
-
-
- /*
- * ChildMessage method - OVERRIDE
- *
- * Handles kExpanderChildSelect messages. We don't handle the selection message
- * in this class. Derived classes must. However, we do check to see if we are at
- * the top of the family tree (parent == NULL), and if so, we echo the selection
- * message back down the tree. This two-stage process is necessary to properly
- * handle the selection of children within children.
- */
-
- void CExpanderPane :: ChildMessage( CFamily *aChild, long message, void *param )
- {
- if ( message == kExpanderChildSelect ) {
- if ( itsParent ) { // still can go up the tree
- TellParent( message, param );
- }
- else { // at root of tree - send message back to leaves
- TellChildren( message, param );
- }
- }
- else {
- CColumnizer::ChildMessage( aChild, message, param );
- }
- }
-
-
- /*
- * ParentMessage method - OVERRIDE
- *
- * Handles kExpanderChildSelect messages. When we receive this message from
- * our parent, we check to see if the parameter is us. If so, we become selected.
- * Otherwise, ignore it.
- */
-
- void CExpanderPane :: ParentMessage( long message, void *param )
- {
- if ( message == kExpanderChildSelect ) {
- Boolean newSel = (CFamily *)param == PaneToChild();
- if ( newSel != selected ) { // may be on or off
- selected = newSel;
- BecomeGopher( newSel ); // become/relinquish gopher
- Refresh(); // regardless, redraw to add/remove hilighting
- }
- }
-
- CColumnizer::ParentMessage( message, param );
- }
-
-
- /*
- * HiliteSelf method
- *
- * Utility method that properly hilites the frame of the pane. Should be called as the last
- * thing to do in a pane's Draw() method.
- */
-
- void CExpanderPane :: HiliteSelf( Boolean state )
- {
- if ( ! printing && IsSelected() ) {
- LongRect aFrame;
- Rect qdRect;
-
- Prepare();
-
- GetFrame( &aFrame );
- FrameToQDR( &aFrame, &qdRect );
-
- TCLSetHiliteMode();
- InvertRect( &qdRect );
-
- if ( ! state ) {
- InsetRect( &qdRect, 1, 1 );
- TCLSetHiliteMode();
- InvertRect( &qdRect );
- }
- }
- }
-
-
- /*
- * PutTo method - OVERRIDE
- *
- * Writes to the stream all of the info we need to save.
- */
-
- void CExpanderPane :: PutTo( CStream &stream )
- {
- stream << selected << canSelect;
-
- CPane::PutTo( stream ); // let our CPane parent access stream
- CColumnizer::PutTo( stream ); // let our CColumnizer parent access stream
- }
-
-
- /*
- * GetFrom method - OVERRIDE
- *
- * Reads from the stream all of the info that we saved.
- */
-
- void CExpanderPane :: GetFrom( CStream &stream )
- {
- stream >> selected >> canSelect;
-
- CPane::GetFrom( stream ); // let our CPane parent access stream
- CColumnizer::GetFrom( stream ); // let our CColumnizer parent access stream
- }
-